package com.zjb.demo.system.controller;

import cn.hutool.core.util.StrUtil;
import com.zjb.demo.common.domain.request.RegisterBody;
import com.zjb.demo.common.domain.response.AjaxResult;
import com.zjb.demo.framework.web.service.RegisterService;
import com.zjb.demo.system.service.SysConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.noear.solon.annotation.*;

/**
 * @author 庄佳彬
 * @since 2023/12/31 00:26
 */
@Controller
@Mapping
@Api(tags = "用户注册")
public class RegisterController {
    @Inject
    private RegisterService registerService;
    @Inject
    private SysConfigService configService;

    @Post
    @Mapping("/register")
    @ApiOperation(value = "注册")
    public AjaxResult<Void> register(@Body RegisterBody registerBody) {
        if (!"true".equals(configService.getValueByKey("sys.account.registerUser"))) {
            return AjaxResult.fail("当前系统没有开启注册功能！");
        }
        var msg = registerService.register(registerBody);
        return StrUtil.isNotEmpty(msg) ? AjaxResult.fail(msg) : AjaxResult.success();
    }
}
